<template>

  <div class="app-container" style="font-size:12px">
    <div class="filter-container">
      <el-date-picker v-model="listQuery.date1" style="width:150px;" format="yyyy-MM-dd" type="datetime" placeholder="订单开始日" />
      <el-date-picker v-model="listQuery.date2" style="width:150px" format="yyyy-MM-dd" type="datetime" placeholder="订单结束日" />
      <el-input v-model="listQuery.customer" placeholder="客户姓名" style="width: 100px;margin-top:6px" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.plates" placeholder="车牌号" style="width: 100px;margin-top:6px" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.c_id" placeholder="选择门店" filterable class="filter-item" style="width:150px;margin-top:8px">
        <el-option label="选择门店" value="" />
        <el-option
          v-for="item in company_list"
          :key="item.id"
          :label="item.c_name"
          :value="item.id"
        />
      </el-select>
      <onwerCompany ref="owner_company" />
      <el-select v-model="listQuery.sale_id" placeholder="选择市场人员" filterable class="filter-item" style="width:150px;margin-top:6px">
        <el-option label="选择市场人员" value="" />
        <el-option
          v-for="item in sale_list"
          :key="item.sale_id"
          :label="item.real_name"
          :value="item.sale_id"
        />
      </el-select>
      <el-select v-model="listQuery.shareholder" placeholder="股东" class="filter-item" style="width:130px;margin-top:8px">
        <el-option label="股东" value="" />
        <el-option
          v-for="item in shareholderList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>

      <el-select v-model="listQuery.order_status" placeholder="订单状态" class="filter-item" style="width:150px;margin-top:6px">
        <el-option label="订单状态" value="" />
        <el-option label="进行中" value="1" />
        <el-option label="已完成" value="3" />
        <el-option label="待收" value="4" />
        <!-- <el-option label="终止" value="5" /> -->
      </el-select>

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:6px" @click="handleFilter">查询</el-button>
      <!-- <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="excelout">导出</el-button> -->
      <excel />
    </div>
    <el-row style="margin-top:20px;font-size:14px;color:#666">
      <el-col :span="5">融资总额：{{ allcount.allmoney }}</el-col>
      <el-col :span="5">应收总额：{{ allcount.all_amount_money }}</el-col>
      <el-col :span="5">已收总额：{{ allcount.all_payed_money }}</el-col>
      <el-col :span="5">未收总额：{{ allcount.all_no_payed_money }}</el-col>

    </el-row>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" size="mini" :row-class-name="tableRowClassName" border fit highlight-current-row style="width: 100%;margin-top:20px">
      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
          <el-dropdown :hide-on-click="false">
            <span class="el-dropdown-link" style="color:#67C23A">
              更多操作
              <i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="nodes.indexOf('159')!=-1">
                <el-button type="primary" size="mini" @click="toPayment(row.order_id,row)">
                  租金计划
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item v-if="nodes.indexOf('160')!=-1">
                <el-button type="success" size="mini" @click="shareholder(row.order_id,row)">
                  股东占比
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item v-if="nodes.indexOf('161')!=-1">
                <el-button type="info" size="mini" @click="outcomeInput(row.order_id,row)">
                  支出录入
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item v-if="nodes.indexOf('162')!=-1">
                <el-button type="warning" size="mini" @click="incidental(row.order_id,row)">
                  杂费回款
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item v-if="nodes.indexOf('163')!=-1">
                <el-button type="primary" size="mini" @click="changeStatus(row.order_id,row)">
                  更改状态
                </el-button>
              </el-dropdown-item>
              <!-- <el-dropdown-item>
                <el-button type="success" size="mini" @click="change_owner(row.order_id,row)">
                  过户公司
                </el-button>
              </el-dropdown-item> -->
              <el-dropdown-item v-if="nodes.indexOf('164')!=-1">
                <el-button type="primary" size="mini" @click="profitCount(row.order_id,row)">
                  利润计算
                </el-button>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button type="default" size="mini" @click="desc(row.order_id,row)">
                  备注信息
                </el-button>
              </el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
      <el-table-column label="编号" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.order_contract_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注信息" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.descript }}</span>
        </template>
      </el-table-column>
      <el-table-column label="门店" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.c_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="首次还款日期" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.first_payment_day }}
        </template>
      </el-table-column>
      <el-table-column label="租车日期" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.create_time }}
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.plate_no }}
        </template>
      </el-table-column>
      <el-table-column label="车型" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.model_name }}
        </template>
      </el-table-column>
      <el-table-column label="车架号" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.vin }}
        </template>
      </el-table-column>
      <el-table-column label="还款周期" align="center" width="100px">
        <template slot-scope="{row}">
          {{ row.days }}/天
        </template>
      </el-table-column>

      <el-table-column label="客户名称" align="center">
        <template slot-scope="{row}">
          <span style="color:dodgerblue;cursor: pointer" @click="toPayment(row.order_id)">{{ row.real_name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="客户电话" align="center" width="120px">
        <template slot-scope="{row}">
          <span>{{ row.mobile }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证" align="center" width="150px">
        <template slot-scope="{row}">
          <span>{{ row.idcard }}</span>
        </template>
      </el-table-column>
      <el-table-column label="购车款" align="center">
        <el-table-column label="总金额" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.all_price_all }}</span>
          </template>
        </el-table-column>
        <el-table-column label="首付款" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.first_price }}</span>
          </template>
        </el-table-column>
        <el-table-column label="融资款" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.total_price }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="租金" align="center">
        <el-table-column label="应收" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.all_price }}</span>
          </template>
        </el-table-column>
        <el-table-column label="已收" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.paid_money }}</span>
          </template>
        </el-table-column>
        <el-table-column label="未收" align="center" width="80px">
          <template slot-scope="{row}">
            <span>{{ row.no_paid_money }}</span>
          </template>
        </el-table-column>
      </el-table-column>

      <!-- <el-table-column label="本金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.benjin }}</span>
        </template>
      </el-table-column>

      <el-table-column label="总金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.total_price }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="每期租金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.a_month_price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总期数" align="center" width="70px">
        <template slot-scope="{row}">
          <span>{{ row.total_period }}</span>
        </template>
      </el-table-column>
        <el-table-column label="已收期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.payed_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加融期数" align="center" width="80px">
        <template slot-scope="{row}">
          <span>{{ row.jiarong_qs }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加融金额" align="center" width="80px">
        <template slot-scope="{row}">
          <span>{{ row.jiarong_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="未付加融期数" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.no_paid_jiarong_qs }}</span>
        </template>
      </el-table-column>

      <el-table-column label="流量费" align="center">
        <template slot-scope="{row}">
          <span>{{ row.flow }}</span>
        </template>
      </el-table-column>
      <el-table-column label="杂费回款" align="center">
        <template slot-scope="{row}">
          <span>{{ row.incidental_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支出费用" align="center">
        <template slot-scope="{row}">
          <span>{{ row.outcome_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="费率" align="center">
        <template slot-scope="{row}">
          <span>{{ row.rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="剩余本金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.no_paid_benjin }}</span>
        </template>
      </el-table-column>

    
      <el-table-column label="提前结清金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.before_settle_money }}</span>
        </template>
      </el-table-column>

      <el-table-column label="逾期天数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.all_overdue_days }}</span>
        </template>
      </el-table-column>

      <el-table-column label="结清日期" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.pay_completed_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.goods_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进件人" align="center">
        <template slot-scope="{row}">
          <span>{{ row.sale_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出资公司" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.onwer_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="初审" align="center" width="70">
        <template slot-scope="{row}">
          <span>{{ row.first_admin_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="复审" align="center" width="70">
        <template slot-scope="{row}">
          <span>{{ row.second_admin_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="制单" align="center" width="70">
        <template slot-scope="{row}">
          <span>{{ row.third_admin_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终审" align="center" width="70">
        <template slot-scope="{row}">
          <span>{{ row.fourth_admin_name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="当前状态" align="center">
        <template slot-scope="{row}">
          <span>{{ row.status_name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="合同编号" align="center" width="180px">
        <template slot-scope="{row}">
          <span>{{ row.contract_num.contract_no }}</span>
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-dialog title="支出录入" :visible.sync="outcomeInputAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="other_form" label-width="120px">
        <el-form-item label="支出费用">
          <el-input v-model="other_form.outcome_money" type="number" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="serverAllMoneySubmit(1)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="杂费回款" :visible.sync="incidentalAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="other_form" label-width="120px">
        <el-form-item label="杂费回款">
          <el-input v-model="other_form.incidental_money" type="number" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="serverAllMoneySubmit(2)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="更改状态" :visible.sync="changeStatusAble" v-dialog-drag  style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="status_form" label-width="120px">
        <el-form-item label="状态">
          <el-select v-model="other_form.status" placeholder="状态" style="width: 180px">
            <el-option label="进行中" :value="1" />
            <el-option label="已完成" :value="3" />
            <el-option label="待收" :value="4" />
            <el-option label="终止" :value="100" />
          </el-select>
        </el-form-item>
        <el-form-item label="待收状态"  v-if="other_form.status==4">
          <el-select v-model="other_form.ds_status" placeholder="待收状态" style="width: 180px">
            <el-option label="收回" :value="1" />
            <el-option label="提前结清" :value="2" />
            <el-option label="疑难" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="负责人"  v-if="other_form.status==4">
          <el-select v-model="other_form.adminuser_id" placeholder="负责人" style="width: 180px" filterable>
            <el-option
              v-for="item in admin_list"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item v-if="other_form.status==100" label="合同支出">
          <el-input v-model="other_form.contract_outcome" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item v-if="other_form.status==100" label="合同支出日期">
          <el-date-picker v-model="other_form.contract_outcome_date" style="width:180px;" format="yyyy-MM-dd" type="datetime" placeholder="合同支出日期" />
        </el-form-item>
        <el-form-item v-if="other_form.status==100" label="合同收入">
          <el-input v-model="other_form.contract_income" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item v-if="other_form.status==100" label="合同收入日期">
          <el-date-picker v-model="other_form.contract_income_date" style="width:180px;" format="yyyy-MM-dd" type="datetime" placeholder="合同收入日期" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="serverAllMoneySubmit(4)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="利润计算" :visible.sync="profitCountAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="profitCount_form" label-width="140px">

        <el-form-item label="总融资金额">
          <el-input v-model="profitCount_form.total_price" disabled type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="总融租金">
          <el-input v-model="profitCount_form.all_price" disabled type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="总已收">
          <el-input v-model="profitCount_form.paid_money" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="总开支">
          <el-input v-model="profitCount_form.outcome_money" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="选择股东">
          <el-select v-model="profitCount_form.shareholder" placeholder="选择股东" style="width: 180px" @change="selectShareholder()">
            <el-option label="选择股东" value="" disabled />
            <el-option
              v-for="(item,key) in shareholder_from.datas"
              :key="key"
              :label="item.shareholder_name"
              :value="key"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="股东本金">
          <el-input v-model="profitCount_form.benjin" disabled type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="股东已结算">
          <el-input v-model="profitCount_form.settle_money" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="本金占比">
          <el-input v-model="profitCount_form.percentage" disabled type="number" style="width: 180px" />
        </el-form-item>
        <!-- <el-form-item  label="租金收益分利占比">
          <el-input v-model="profitCount_form.profit_percentage"  type="number" style="width: 180px" />
        </el-form-item> -->
        <el-form-item label="合同收益">
          <el-input v-model="profitCount_form.contract_profit" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="合同收益分利占比">
          <el-input v-model="profitCount_form.contract_profit_percentage" type="number" style="width: 180px" />
        </el-form-item>
        <el-form-item label="最终计算结果">
          <el-input v-model="end_profit" readonly type="number" style="width: 180px" />
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="countSubmit(4)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="过户公司" :visible.sync="changeOwnerAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="change_owner_form" label-width="120px">
        <el-form-item label="过户公司">
          <el-select v-model="change_owner_form.owner_id" placeholder="过户公司" class="filter-item" style="width:130px;margin-top:8px">
            <el-option label="过户公司" value="" :aria-disabled="true" />
            <el-option
              v-for="item in transfer_ownership_company_list"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="changeOwnerAbleSubmit(4)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="备注信息" :visible.sync="descAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="other_form" label-width="120px">
        <el-form-item label="备注信息">
          <el-input v-model="other_form.desc" type="text" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="serverAllMoneySubmit(3)">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="股东占比" :visible.sync="shareholderAble" style="width:2000px;margin:auto">
      <el-form ref="dataForm" :inline="true" :model="shareholder_from" label-width="80px">
        <div v-for="(item,k) in shareholder_from.datas" :key="k" style="border-bottom: 1px solid #eee;height: 50px;padding-top: 7px;">
          <el-form-item label="股东">
            <el-select v-model="item.shareholder" placeholder="股东" style="width: 80px">
              <el-option
                v-for="item in shareholderList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="本金">
            <el-input v-model="item.money" placeholder="本金(元)" style="width: 80px" />
          </el-form-item>
          <el-form-item label="占比">
            <el-input v-model="item.percentage" placeholder="1-10成" style="width: 80px" @change="caculer(k)" />
          </el-form-item>
          <el-form-item label="月供分利">
            <el-input v-model="item.benefits" placeholder="1-10成" style="width: 80px" />
          </el-form-item>
          <el-form-item>
            <el-button v-if="k==0" type="primary" size="mini" @click="addDocument()">+</el-button>
            <el-button v-else type="info" size="mini" @click="delDocument(k)">X</el-button>
          </el-form-item>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="is_system==1||ishavedshareholder==0" type="primary" @click="orderShareHolderSet(2)">确 定</el-button>
      </span>
    </el-dialog>

  </div>

</template>

<script>
import excel from '@/components/excelout/index.vue'
import {
  getNodes
} from '@/utils'
import {
  financeOrderList, exceloutfinanceList, returnOrderSubmit, serverAllMoneySubmit, orderShareHolderSet, getShareHolder,
  getThisOrderShareHolder, transferOwnershipCompany, changeOwnerAbleSubmit
} from '@/api/finance'
import { formatDate } from '@/utils/formatDate.js'
import { merchantListOnlyMerchant } from '@/api/merchant'
import { fetchList } from '@/api/sale'
import waves from '@/directive/waves' // waves directive
import {
  parseTime
} from '@/utils'
import onwerCompany from '@/components/company/owner_company.vue'
import { getAllList } from '@/api/user'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination, excel, onwerCompany
  },
  directives: {
    waves
  },
  filters: {
   	formatDate(time) {
   	        time = time * 1000
   	        const date = new Date(time)

   	        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
   	      }
  },
  data() {
    return {
      nodes:[],
      ishavedshareholder: 0,
      is_system: 0,
      query: {
        page: 1,
        limit: 500,
        role_id:7,
      },
      end_profit: 0,
      profitCount_form: {
        outcome_money: 0,
        end_profit: 0
      },
      profitCountAble: false,
      change_owner_form: {
        order_id: '',
        owner_id: ''
      },
      transfer_ownership_company_list: [],
      shareQuery: {
        limit: 100
      },
      status_form: {
        status: 0
      },
      shareholderList: [],
      other_form: {
        order_id: '',
        money: '',
        desc: '',
        incidental_money: '',
        outcome_money: '',
        status: '0',
        contract_outcome: 0,
        contract_income: 0,
        contract_outcome_date: '',
        contract_income_date: ''
      },
      shareholder_from: {
        order_id: '',
        datas: [
          {
            shareholder: '',
            money: '',
            percentage: '',
            benefits: ''
          }
        ]
      },
      changeOwnerAble: false,
      changeStatusAble: false,
      admin_list: [],
      tableKey: 0,
      shareholderAble: false,
      descAble: false,
      outcomeInputAble: false,
      incidentalAble: false,
      tableRecord: 1,
      list: null,
      record_list: null,
      listRecordLoading: true,
      recordTotal: 0,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        customer: '',
        c_id: '',
        sale_id: '',
        order_status: '',
        excel: 0,
        plates: '',
        flag: 1,
        date1: '',
        date2: '',
        shareholder: ''
      },
      listMerchantQuery: {
        page: 1,
        limit: 500
      },
      allcount: [],
      company_list: [],
      sale_list: [],
      form: []
    }
  },
  created() {
    this.cacheQueryFormat()
    this.is_system = localStorage.getItem('is_system')
    this.getShareHolder()
    this.listQuery.shareholder = this.$route.query.shareholder
    this.getCompanyList()
    this.getList()
    this.nodes = getNodes()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  destroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    getAllList() {
      getAllList(this.query).then(response => {
        this.admin_list = response.data
      })
    },
    countSubmit() {
      // 应收
      const zje = parseFloat(this.profitCount_form.paid_money) + parseFloat(this.profitCount_form.contract_profit)// 总金额

      const zsy = zje - parseFloat(this.profitCount_form.outcome_money) - parseFloat(this.profitCount_form.total_price)// 总收益

      const one_sy = zsy * parseFloat(this.profitCount_form.contract_profit_percentage) / 10// 个人收益

      // 减去已结算
      const end = one_sy - parseFloat(this.profitCount_form.settle_money) + parseFloat(this.profitCount_form.benjin)
      console.log(end)
      this.end_profit = end
    },
    selectShareholder() {
      this.profitCount_form.settle_money = this.shareholder_from.datas[this.profitCount_form.shareholder].settle_money
      this.profitCount_form.benjin = this.shareholder_from.datas[this.profitCount_form.shareholder].money
      this.profitCount_form.percentage = this.shareholder_from.datas[this.profitCount_form.shareholder].percentage
    },
    profitCount(order_id, row) {
      this.profitCountAble = true
      this.profitCount_form = row
      this.profitCount_form.benjin = 0
      this.profitCount_form.settle_money = 0
      this.profitCount_form.percentage = 0
      this.profitCount_form.end_profit = 0
      this.getThisOrderShareHolder(order_id)
    },
    addDocument() {
      const o = { shareholder: '', money: '', percentage: '' }
      this.shareholder_from.datas.push(o)
    },
    getShareHolder(order_id) {
      getShareHolder(this.shareQuery).then(response => {
        this.shareholderList = response.data.data
      })
      this.getThisOrderShareHolder(order_id)
    },
    getThisOrderShareHolder(order_id) {
      const pam = { order_id: order_id }
      getThisOrderShareHolder(pam).then(response => {
        // this.thisOrderShareholder = response.data.data;
        this.shareholder_from.datas = [
          {
            shareholder: '',
            money: '',
            percentage: '',
            benefits: ''
          }
        ]
        if (response.data.data.length > 0) {
          this.ishavedshareholder = 1

          this.shareholder_from.datas = response.data.data
        }
      })
    },
    delDocument(k) {
      this.shareholder_from.datas.map((item, index) => {
        if (index == k) {
          this.shareholder_from.datas.splice(index, 1)
        }
      })
    },
    caculer(k) {
      this.shareholder_from.datas.map((item, index) => {
        if (index == k) {
          this.shareholder_from.datas[k].money = this.shareholder_from.datas[k].percentage * this.shareholder_from.total_money / 10
        }
      })
    },
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('financeList')
      sessionStorage.removeItem('to_order_id')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('financeList')
      const to_order_id = sessionStorage.getItem('to_order_id')
      if (cacheQuery) {
        this.listQuery = JSON.parse(cacheQuery)
      }
      if(to_order_id){
        this.listQuery.order_id = to_order_id;
      }
    },
    getList() {
      sessionStorage.setItem('financeList', JSON.stringify(this.listQuery))
      financeOrderList(this.listQuery).then(response => {
        if (!this.listQuery.excel) {
          this.list = response.data.list.data
          this.total = response.data.list.total
          this.allcount = response.data.countall

          setTimeout(() => {
            this.listLoading = false
          }, 0.1 * 1000)
        } else {
          this.listQuery.excel = 0
        }
      })
    },
    outcomeInput(order_id, row) {
      this.outcomeInputAble = true
      this.other_form.order_id = order_id
      this.other_form.outcome_money = row.outcome_money
    },
    changeStatus(order_id, row) {
      this.changeStatusAble = true;
      this.other_form.order_id = order_id
      this.other_form.status = row.status
      this.other_form.contract_outcome = row.contract_outcome
      this.other_form.contract_income = row.contract_income
      this.other_form.contract_income_date = row.contract_income_date
      this.other_form.contract_outcome_date = row.contract_outcome_date
      this.getAllList()
    },
    changeOwnerAbleSubmit() {
      changeOwnerAbleSubmit(this.change_owner_form).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.changeOwnerAble = false
      })
    },
    change_owner(order_id, row) {
      this.changeOwnerAble = true
      this.change_owner_form.order_id = order_id
      this.getChangeOnerCompanyList()
    },
    shareholder(order_id, row) {
      this.shareholderAble = true
      this.shareholder_from.order_id = order_id
      this.shareholder_from.total_money = row.total_price
      this.getShareHolder(order_id)
    },
    incidental(order_id, row) {
      this.incidentalAble = true
      this.other_form.order_id = order_id
      this.other_form.incidental_money = row.incidental_money
    },
    desc(order_id, row) {
      this.descAble = true
      this.other_form.order_id = order_id
      this.other_form.desc = row.descript
    },
    returnOrderSubmit() {
      returnOrderSubmit(this.form).then(response => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.returnOrderAble = false
      })
    },

    orderShareHolderSet() {
      orderShareHolderSet(this.shareholder_from).then(response => {
        if (response.code == 200) {
          this.$notify({
            title: '提示',
            message: response.msg,
            type: 'success',
            duration: 2000,
            onClose: this.getList()
          })
          this.shareholderAble = false
        } else {
          this.$notify({
            title: '提示',
            message: response.msg,
            type: 'error',
            duration: 2000
          })
        }
      })
    },
    serverAllMoneySubmit(lab) {
      this.other_form.lab = lab
      serverAllMoneySubmit(this.other_form).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.outcomeInputAble = false
        this.incidentalAble = false
        this.descAble = false
      })
    },
    serverAllMoneySubmit(lab) {
      this.other_form.lab = lab
      serverAllMoneySubmit(this.other_form).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.outcomeInputAble = false
        this.incidentalAble = false
        this.changeStatusAble = false
        this.descAble = false
      })
    },
    handleFilter() {
      this.listLoading = true
      const owner_company_id = this.$refs.owner_company.$data.listQuery.company_id
      this.listQuery.owner_company_id = owner_company_id
      this.listQuery.page = 1
      this.getList()
    },

    excelout() {
      this.listLoading = true
      this.listQuery.page = 1
      this.listQuery.limit = this.total
      exceloutfinanceList(this.listQuery).then(response => {
        this.listLoading = false
        const filepath = response.data.path
        window.location.href = filepath
      })
    },

    getCompanyList() {
      merchantListOnlyMerchant(this.listMerchantQuery).then(response => {
        this.company_list = response.data.company
        this.sale_list = response.data.sale.data
      })
    },
    getChangeOnerCompanyList() {
      transferOwnershipCompany().then(response => {
        this.transfer_ownership_company_list = response.data
      })
    },
    toPayment(order_id) {
      this.$router.push('/finance/customerpayment/' + order_id)
    },

    handleRecord(order_id) {
      console.log(order_id)
      this.dialogStatus = 'record'
      this.dialogRecordVisible = true
      this.listRecordQuery.order_id = order_id
      fetchOrderRecordListByOrderId(this.listRecordQuery).then(res => {
        this.record_list = res.data.list
        this.recordTotal = res.data.count
        setTimeout(() => {
          this.listRecordLoading = false
        }, 1.0 * 1000)
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.s == 1) {
        return 'success-row'
      } else if (row.s == 2) {
        return 'warning-row'
      } else if (row.s == 3) {
        return 'default-row'
      } else if (row.s == 4) {
        return 'tips-row'
      }
      return ''
    }

  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
  }
  td{padding: 0;}
  select{
    width:100px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
    float: left;
  }
   .el-table .warning-row {
      background: orangered;
    }
    .el-table .tips-row {
      background:goldenrod;
    }

  .el-table .success-row {
    background: #98dd72;
  }
  .el-table .default-row {
    background: #ccc;
  }
</style>
